Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes disabled color on buttonView when no colorCode is passed & refactor #4934

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

manivoxel51
Copy link
Contributor

@manivoxel51 manivoxel51 commented Oct 16, 2024

What changes are proposed in this pull request?

Fixes disabled color on buttonView when no colorCode is passed & refactor

How is this patch tested? If it is not, please explain why.

snippet below for testing

Screen Shot 2024-10-16 at 9 29 52 AM
import fiftyone.operators as foo
import fiftyone.operators.types as types


class Snippet(foo.Panel):
    @property
    def config(self):
        return foo.PanelConfig(name="Snippet", label="Snippet")

    def increment(self, ctx):
        ctx.panel.state.my_count += 1

    def render(self, ctx):
        panel = types.Object()

        # contained enabled
        panel.btn(
            "hello_btn",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="contained",
            color="primary",
            disabled=False,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        panel.btn(
            f"compute_button",
            label=f"Scanning Dataset",
            variant="contained",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # contained disabled
        panel.btn(
            "hello_btn2",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="contained",
            color="primary",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # contained enabled secondary
        panel.btn(
            "hello_btn3",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="contained",
            color="secondary",
            disabled=False,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # contained disabled secondary
        panel.btn(
            "hello_btn4",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="contained",
            color="secondary",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # square disabled
        panel.btn(
            "hello_btn5",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="square",
            color="primary",
            disabled=False,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # square disabled
        panel.btn(
            "hello_btn6",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="square",
            color="primary",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # round enabled
        panel.btn(
            "hello_btn7",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="round",
            color="primary",
            disabled=False,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # round disabled
        panel.btn(
            "hello_btn8",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="round",
            color="primary",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # outlined enabled
        panel.btn(
            "hello_btn9",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="outlined",
            color="primary",
            disabled=False,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        # outlined disabled
        panel.btn(
            "hello_btn10",
            label="Mark as reviewed",
            icon="emoji_people",
            on_click=self.increment,
            variant="outlined",
            color="primary",
            disabled=True,
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        btn_view = types.ButtonView(
            label="Test",
            title="test",
            href="http://voxel51.com",
            params={"message": "Hello World"},
            # color="51",
            color="primary",
            variant="contained",
            disabled=False, # or disabled=False
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        panel.view("btn", btn_view)

        btn_view_2 = types.ButtonView(
            label="Test",
            title="test",
            href="http://voxel51.com",
            params={"message": "Hello World"},
            # color="51",
            color="primary",
            variant="contained",
            disabled=True, # or disabled=False
            componentsProps={'button': {'sx': {'width': '200px', 'ml': '30%', 'mt': '10px'}}}
        )

        panel.view("btn_2", btn_view_2)

        return types.Property(panel)



def register(p):
    p.register(Snippet)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Improved handling of disabled button states for better visual feedback.
  • Bug Fixes

    • Streamlined logic for determining disabled button colors, enhancing clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes involve modifications to the ButtonView component in ButtonView.tsx and the getDisabledColors function in style.ts. The ButtonView component now simplifies the logic for handling disabled button states by consolidating conditions and refining color determination. The getDisabledColors function has been updated to remove its parameter, returning a fixed array of color values instead. These updates enhance the clarity and efficiency of the code without altering any public entity declarations.

Changes

File Change Summary
app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx Refined logic for disabled button states; simplified background color checks for "square" and "outlined" variants.
app/packages/core/src/plugins/SchemaIO/utils/style.ts Updated getDisabledColors to remove its parameter; now returns a fixed array of color values.

Possibly related PRs

Suggested labels

app

Suggested reviewers

  • lanzhenw
  • imanjra
  • Br2850

🐇 In the garden where colors gleam,
The buttons dance, a vibrant dream.
With logic clear, they stand so bright,
Disabled hues, a lovely sight.
A hop, a skip, through code we play,
Refining paths in a joyful way! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@Br2850 Br2850 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏽

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/packages/core/src/plugins/SchemaIO/utils/style.ts (1)

Line range hint 1-46: Consider reviewing color code usage across the application

While getDisabledColors has been simplified, getColorByCode and the ColorType definition remain unchanged. This suggests that color codes are still used elsewhere in the application. To ensure consistency:

  1. Review the usage of getColorByCode and getDisabledColors across the application to ensure they are used appropriately.
  2. Consider if getColorByCode could benefit from a similar simplification as getDisabledColors.
  3. Evaluate if the ColorType definition needs to be updated or if it's still relevant for other parts of the application.

To help with this review, you could run the following script:

#!/bin/bash
# Description: Analyze color-related function usage across the application
# Expected result: A list of files and lines where color-related functions are used

echo "Files using getColorByCode:"
rg --type typescript "getColorByCode\(" -l

echo "Files using getDisabledColors:"
rg --type typescript "getDisabledColors\(" -l

echo "Files referencing ColorType:"
rg --type typescript "ColorType" -l

This will help identify areas of the application that might be affected by the changes to getDisabledColors and guide further refactoring if necessary.

app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (1)

Line range hint 110-119: Approved changes with a suggestion for improvement

The refactoring of the disabled button color logic looks good. The simplification of the condition for "square" and "outlined" variants improves code readability.

However, to enhance type safety, consider using a const array for the variant check:

const VARIANTS_WITH_FIELD_BACKGROUND = ['square', 'outlined'] as const;
// ...
if (VARIANTS_WITH_FIELD_BACKGROUND.includes(variant as typeof VARIANTS_WITH_FIELD_BACKGROUND[number])) {
  // ...
}

This approach ensures that only valid variant values are used in the condition.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d0ba069 and 7bedaa7.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/utils/style.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/utils/style.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/core/src/plugins/SchemaIO/utils/style.ts (1)

11-12: Simplified getDisabledColors function may impact disabled element styling

The getDisabledColors function has been simplified to always return a fixed array of color values. While this change aligns with the PR objective of fixing the disabled color when no colorCode is passed, it has some implications:

  1. It removes the flexibility to have different disabled colors based on the input color code.
  2. It may affect the visual appearance of disabled buttons or other UI elements using this function.
  3. Components using this function no longer need to pass a color code, which could simplify their implementation.

Please ensure that this change doesn't negatively impact the disabled state styling across different components in the application. Consider adding a comment explaining the reasoning behind this change for future maintainers.

To verify the impact of this change, please run the following script:

✅ Verification successful

Verification Successful: getDisabledColors is Used Correctly Without Arguments

The getDisabledColors function is consistently called without arguments across the codebase, confirming that the recent changes have been correctly implemented. No instances of getDisabledColors being invoked with arguments were found, ensuring that the function's simplification does not introduce any unintended issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usages of getDisabledColors function
# Expected result: No instances of getDisabledColors being called with arguments

# Search for getDisabledColors usage
echo "Searching for getDisabledColors usage:"
rg --type typescript "getDisabledColors\(" -A 2

# Search for disabled button styling
echo "Searching for disabled button styling:"
rg --type typescript "disabled.*style|style.*disabled" -A 2

Length of output: 355


Script:

#!/bin/bash
# Description: Check for usages of getDisabledColors function without specifying file type
# Expected result: No instances of getDisabledColors being called with arguments

# Search for getDisabledColors usage
echo "Searching for getDisabledColors usage:"
rg "getDisabledColors\(" -A 2

# Search for disabled button styling
echo "Searching for disabled button styling:"
rg "disabled.*style|style.*disabled" -A 2

Length of output: 51767

@manivoxel51 manivoxel51 merged commit 16ea2a5 into feat/fo-assistant Oct 16, 2024
7 of 10 checks passed
@manivoxel51 manivoxel51 deleted the bug/disabled-button branch October 16, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants